<?php
class Custom_View_Helper_Addstylesheet extends Zend_View_Helper_Abstract
{
    public function addStylesheet($file, $position = '', $media = 'screen',
        $conditionalStylesheet = true)
    {
        $positions   = array('first', '', 'last');
        if (!in_array($position, $positions, true)) {
            throw new Custom_View_Exception(sprintf(
                'The position "%s" does not exist (available positions: %s).',
                $position, implode(', ', $positions)
            ));
        }

        $module = Zend_Controller_Front::getInstance()->getRequest()->getModuleName();
        $css = $this->view->baseUrl() . $this->view->pathSkin . $module.'/'.
            $this->view->{$module}['template'] .'/css/' . $file;

        switch ($position){
            case 'first':
                $this->view->headLink()->prependStylesheet(
                    $css, $media, $conditionalStylesheet
                );
                break;
            case '':
                $this->view->headLink()->appendStylesheet(
                    $css, $media, $conditionalStylesheet
                );
                break;
            case 'last':
                $this->view->headLink()->offsetSetStylesheet(
                    100, $css, $media, $conditionalStylesheet
                );
                break;
        }
    }
}